package com.ayq.activiti.manager.controller;

import com.ayq.activiti.manager.service.CustomModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ActivitiException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.InputStream;


@RestController
@RequestMapping("/service")
@Api(tags = "流程模型web配置中心")
@Slf4j
public class StencilsetRestResource {
  protected static final Logger LOGGER = LoggerFactory.getLogger(StencilsetRestResource.class);
  @Autowired
  private CustomModelService customModelService;

  /**
   * <p>获取对应系统流程菜单并汉化</p>
   * <p>方法名:getStencilset</p>
   * @Author ayq
   * @Date 2021/3/8 16:15
   * @Param []
   * @Return java.lang.String
   */
  @ApiOperation(value = "获取对应系统流程菜单并汉化", notes = "获取对应系统流程菜单并汉化")
  @RequestMapping(value="/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
  public @ResponseBody String getStencilset() {
    InputStream stencilsetStream = null;
    try {
      return customModelService.getStencilset(stencilsetStream);
    } catch (Exception e) {
      LOGGER.error("获取对应系统流程菜单并汉化出错",e);
      throw new ActivitiException("获取对应系统流程菜单并汉化出错", e);
    } finally {
      if (stencilsetStream != null){
        try {
          stencilsetStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
}
